package com.ruoyi.bloom;

import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/bloom")
public class BloomFilterTestController {

    @Autowired
    private UserService userService;

    @GetMapping("/add")
    public AjaxResult add(Long userId) throws IOException {
        userService.addToBloomFilter(userId);
        return AjaxResult.success();
    }

    @GetMapping("/isExist")
    public AjaxResult isExist(Long userId) throws IOException {
        // 判断存在（可能误判）
        if(userService.mightContain(userId)){
            return AjaxResult.success("存在");
        }
        return AjaxResult.error("不存在");
    }

    @GetMapping("/isNotExist")
    public AjaxResult isNotExist(Long userId) throws IOException {
        // 判断不存在（绝对准确）
        if(!userService.mightContain(userId)){
            return AjaxResult.error("不存在");
        }
        return AjaxResult.success("存在");
    }
}
